﻿namespace Aurora.Redis;
/// <summary>
/// redis cache 接口
/// </summary>
public interface IRedisCache : IDisposable
{
    /// <summary>
    /// 添加缓存- 带有过期时间
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    /// <param name="timeSpan"></param>
    /// <returns></returns>
    bool Add(string key, string value, TimeSpan timeSpan);
    /// <summary>
    /// 添加缓存- 带有过期时间
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    /// <param name="timeSpan"></param>
    /// <returns></returns>
    Task<bool> AddAsync(string key, string value, TimeSpan timeSpan);
    /// <summary>
    /// 添加缓存
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    /// <param name="timeSpan"></param>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    bool Add<T>(string key, T value, TimeSpan timeSpan);
    /// <summary>
    /// 添加缓存
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    /// <param name="timeSpan"></param>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    Task<bool> AddAsync<T>(string key, T value, TimeSpan timeSpan);
    /// <summary>
    /// lpop
    /// </summary>
    /// <param name="key"></param>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    T LPop<T>(string key);
    /// <summary>
    /// lpop async 
    /// </summary>
    /// <param name="key"></param>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    Task<T> LPopAsync<T>(string key);

    /// <summary>
    /// 获取 key-value
    /// </summary>
    /// <param name="key"></param>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    T Get<T>(string key);
    Task<T> GetAsync<T>(string key);
    /// <summary>
    /// 删除单个 key
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    long Del(string key);
    Task<long> DelAsync(string key);
    /// <summary>
    /// 根据匹配删除缓存
    /// </summary>
    /// <param name="pattern"></param>
    /// <returns></returns>
    Task<long> DelByPatternAsync(string pattern);

    /// <summary>
    /// 获取keys
    /// </summary>
    /// <param name="pattern"></param>
    /// <returns></returns>
    Task<List<string>> GetKeys(string pattern);


    /// <summary>
    /// 自增
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    /// <param name="ttl"></param>
    /// <returns></returns>
    Task IncrementAsync(string key, int value = 1, TimeSpan? ttl = null);
}